<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "toilet".
 *
 * @property int $t_id
 * @property string $sn
 * @property int $sex
 * @property string $cname
 * @property string $location
 *
 * @property CurrentToilet[] $currentToilets
 * @property Flow[] $flows
 * @property FlowDay[] $flowDays
 * @property FlowMon[] $flowMons
 * @property FlowYr[] $flowYrs
 * @property Gas[] $gas
 * @property Online[] $onlines
 * @property Role[] $roles
 * @property UseHistory[] $useHistories
 */
class Toilet extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'toilet';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['t_id'], 'required'],
            [['t_id', 'sex'], 'integer'],
            [['sn'], 'string', 'max' => 32],
            [['cname', 'location'], 'string', 'max' => 255],
            [['t_id'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            't_id' => 'ID',
            'sn' => '序列号',
            'sex' => '性别',
            'cname' => '名称',
            'location' => '地址',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCurrentToilets()
    {
        return $this->hasMany(CurrentToilet::className(), ['t_id' => 't_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getFlows()
    {
        return $this->hasMany(Flow::className(), ['t_id' => 't_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getFlowDays()
    {
        return $this->hasMany(FlowDay::className(), ['t_id' => 't_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getFlowMons()
    {
        return $this->hasMany(FlowMon::className(), ['t_id' => 't_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getFlowYrs()
    {
        return $this->hasMany(FlowYr::className(), ['t_id' => 't_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGas()
    {
        return $this->hasMany(Gas::className(), ['t_id' => 't_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getOnlines()
    {
        return $this->hasMany(Online::className(), ['t_id' => 't_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getRoles()
    {
        return $this->hasMany(Role::className(), ['t_id' => 't_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUseHistories()
    {
        return $this->hasMany(UseHistory::className(), ['t_id' => 't_id']);
    }
}
